package com.example.test_app

import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.FragmentPagerAdapter
import androidx.fragment.app.FragmentStatePagerAdapter
import androidx.viewpager.widget.ViewPager


class VpFragment : ChildFragment() {

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        var view=inflater.inflate(R.layout.fragment_vp, container, false)
        initView(view)
        return view
    }
    var pageList=ArrayList<Fragment>()
    private fun initView(view:View){
        val vp=view.findViewById<ViewPager>(R.id.vp)

        pageList.add(BlankFragment2())
        pageList.add(BlankFragment2())

        vp?.adapter=object : FragmentPagerAdapter(parentFragmentManager){
            override fun getCount(): Int {
                return pageList.size
            }

            override fun getItem(position: Int): Fragment {
                Log.d("VpFragment", "getItem: "+position)
                return pageList[position]
            }

        }
    }

    override fun onResume() {
        super.onResume()
        Log.d("VpFragment", "onResume: "+(view?.parent as ViewGroup).id )
    }
}